package com.example.easytts.config

import org.springframework.stereotype.Component
import org.springframework.web.servlet.HandlerInterceptor
import jakarta.servlet.http.HttpServletRequest
import jakarta.servlet.http.HttpServletResponse

@Component
class AdminInterceptor : HandlerInterceptor {
    override fun preHandle(request: HttpServletRequest, response: HttpServletResponse, handler: Any): Boolean {
        if (request.requestURI.startsWith("/admin/auth")) return true
        val admin = request.session.getAttribute("admin")
        if (admin == null) {
            response.status = 401
            response.contentType = "application/json"
            response.writer.write("{\"message\":\"未登录\"}")
            return false
        }
        return true
    }
} 